$(function () {
    //获取url
    var url = localStorage.getItem("ajaxUrl");
    //console.log(url);

    $(".icon-left").on("click", function () {
        window.location.href = "heattakeup.html";
    });

    $(".head h1").text(localStorage.getItem("user_name") + "热处理收线记录");

    //点击 刷新 按钮  重新加载页面
    $(".page .head").on("click", "span.icon-refresh-1-copy", function () {
        window.location.href = "heat_lishi.html";
    });

    //获取本人本班收线入库记录
    $.ajax({
        headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
        type: "post",
        url: url + '/app/heat/getWarehousesByHeatUser',
        data: {},
        dataType: 'json',
        json: 'callback',
        success: function (res) {
            if (res.success) {
                var data = res.result;
                var allWeight = 0;
                if (!data || data.length == 0) {
                    $alert("暂无入库记录！");
                } else {
                    $("#ul_data").empty();
                    var data_html = '';
                    for (var i = 0; i < data.length; i++) {
                        data_html += '<li><div class="row no-gutter"><div class="col-90">' +
                            '<p><span>编号：</span><span class="batch sp">' + (data[i].batch ? data[i].batch : "空") + '</span></p>' +
                            '<p><span>排产单：</span><span class="workplanNumber sp">' + (data[i].workplanNumber ? data[i].workplanNumber : data[i].fromWorkplanNumber) + '</span>' +
                            '<span>机台：</span><span class="machine sp">' + (data[i].machine ? data[i].machine : "") + '</span></p>' +
                            '<p><span>规格：</span><span class="specification sp">' + (data[i].inventoryDiameter ? data[i].inventoryDiameter : "") + '</span>' +
                            '<span>钢号：</span><span class="steel sp">' + (data[i].inventorySteel ? data[i].inventorySteel : "") + '</span></p>' +
                            '<p><span>净重：</span><span class="jz sp">' + (data[i].availableQuantity ? data[i].availableQuantity : "") + '</span>' +
                            '<span>人员：</span><span class="user sp">' + data[i].inName + '</span></p>' +
                            '<p><span>时间：</span><span class="in_time sp">' + data[i].inTime + '</span></p>' +
                            '</div><div class="col-10"><span class="icon iconfont icon-dayin pull-right"></span></div>' +
                            '</div></li>';
                        allWeight = accAdd(allWeight, data[i].availableQuantity ? data[i].availableQuantity : 0);
                    }
                    $("#ul_data").append(data_html);
                }
                //改变 总计数
                $(".content div.ul_foot span.sp_js").html($("#ul_data li").length);
                $(".content div.ul_foot span.sp_weight").html(Number(parseFloat(allWeight).toFixed(3)));
            } else {
                console.log(res);
                $alert(res.message);
            }
        },
        error: function (error) {
            console.log(error);
            $alert(error.responseText);
        }
    });

    //点击 打印
    $("#ul_data").on("click", ".col-10", function () {
        var batch = $(this).parent().parent().find("span.batch").text();
        loading_show("打印中...");
        $.ajax({
            headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
            type: "post",
            url: url + '/app/heat/printNumber',
            data: {
                batch: batch
            },
            dataType: 'json',
            json: 'callback',
            success: function (res) {
                if (res.success) {
                    $alert(batch + "打印成功");
                    // 打印 热处理 收线 标签
                    if (res.result) {
                        takeupPrint("heatTakeup", res.result);
                    }
                } else {
                    console.log(res);
                    loading_hide();
                    $alert(res.message);
                }
            },
            error: function (error) {
                console.log(error);
                loading_hide();
                $alert(error.responseText);
            }
        });
    })

});
